//
//  WBWelcomeViewController.m
//  WeiBoOC
//
//  Created by 韩菲菲 on 16/8/12.
//  Copyright © 2016年 韩菲菲. All rights reserved.
//

#import "WBWelcomeViewController.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
#import "WBUserAccountViewModel.h"

@interface WBWelcomeViewController ()

//背景图片
@property (nonatomic , strong) UIImageView *backGroundImageView;

//头像
@property (nonatomic , strong) UIImageView *headImageView;

//显示文字
@property (nonatomic , strong) UILabel *messageLabel;

@end

@implementation WBWelcomeViewController


- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    //更新头像约束
    [self.headImageView mas_updateConstraints:^(MASConstraintMaker *make) {
    
        make.top.mas_equalTo(self.view).mas_offset(100);
    }];
    
    //设置动画
    [UIView animateWithDuration:2 delay:1 usingSpringWithDamping:0.7 initialSpringVelocity:0 options:0 animations:^{
        
        [self.view layoutIfNeeded];
        
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:0.5 animations:^{
            
            //显示label
            self.messageLabel.alpha = 1;
            
            
        } completion:^(BOOL finished) {
            
            //利用通知切换根控制器
            //发送通知
            [[NSNotificationCenter defaultCenter] postNotificationName:WBSwitchRootViewController object:nil];
            
            
            
        }];
        
        
    }];


}








- (UILabel *)messageLabel
{
    if(!_messageLabel)
    {
        _messageLabel = [[UILabel alloc] init];
        //文字显示内容
        _messageLabel.text = @"欢迎回来";
        //文字大小
        _messageLabel.font = [UIFont systemFontOfSize:18];
        //文字颜色
        _messageLabel.textColor = [UIColor darkGrayColor];
        //文字居中
        _messageLabel.textAlignment = NSTextAlignmentCenter;
        //透明度
        _messageLabel.alpha = 0;
    }

    return _messageLabel;

}

//懒加载头像图片
- (UIImageView *)headImageView
{
    if(!_headImageView)
    {
        _headImageView = [[UIImageView alloc] init];
        
        //SDWebImage
        [_headImageView sd_setImageWithURL:[NSURL URLWithString:[WBUserAccountViewModel sharedWBUserAccountViewModel].getUserAccount.avatar_large] placeholderImage:[UIImage imageNamed:@"avatar_default_big"]];
        
        _headImageView.layer.cornerRadius = 45;
        _headImageView.layer.masksToBounds = YES;
        
    }
    
    return _headImageView;
}



//懒加载控件 背景图
- (UIImageView *)backGroundImageView
{
    if(!_backGroundImageView)
    {
    
        _backGroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ad_background"]];
    }

    return _backGroundImageView;

}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}

- (void)setupUI
{
    
    //添加控件
    [self.view addSubview:self.backGroundImageView];
    [self.view addSubview:self.headImageView];
    [self.view addSubview:self.messageLabel];
    //设置约束 背景图
    [self.backGroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.equalTo(self.view).mas_offset(UIEdgeInsetsZero);
        
    }];
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        //大小 90 * 90 距离顶部400 中心X
        make.size.mas_equalTo(CGSizeMake(90, 90));
        make.top.mas_equalTo(self.view).mas_offset(400);
        make.centerX.mas_equalTo(self.view);
        
    }];
    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.mas_equalTo(self.view);
        make.top.equalTo(self.headImageView.mas_bottom).mas_offset(16);
        
        
    }];
    
  
}












@end
